package edu.mobbuzz.web.facade;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import edu.mobbuzz.daf.bean.User;
import edu.mobbuzz.daf.dao.IStreamDao;
import edu.mobbuzz.daf.dao.IUserDao;

public class ManagementFacade extends BaseFacade {
	private IUserDao userDao;
	private IStreamDao streamDao;
	
	public User getUserByPrimaryKey(String username){
		User user = (User)getUserDao().findByPrimaryKey(username);
		return user;
	}
	
	public IUserDao getUserDao() {
		if(userDao==null)
			userDao = (IUserDao)getFactory().getBean("userDao");
		return userDao;
	}
	
	public IStreamDao getStreamDao() {
		if(streamDao==null)
			streamDao = (IStreamDao)getFactory().getBean("streamDao");
		return streamDao;
	}

	public List<User> getUserList(String where, String order){
		List<User> userList = new ArrayList<User>();
		userList = getUserDao().queryForList(where, order);
		
		return userList;
	}
	
	public void removeUser(User user){
		getUserDao().delete(user);
	}
	
	public void addUser(User user){
		try{
			getUserDao().insert(user);
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void updateUser(User user){
		try{
			getUserDao().update(user);
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public List getCountDailyChart(Date twawal, Date twakhir){
		return getStreamDao().getCountDailyChart(twawal, twakhir);
	}
	
	public List getCountMonthlyChart(Date twawal, Date twakhir){
		return getStreamDao().getCountMonthlyChart(twawal, twakhir);
	}
	
	public List getCountYearlyChart(Date twawal, Date twakhir){
		return getStreamDao().getCountYearlyChart(twawal, twakhir);
	}
	
}
